package dao;

import java.util.Date;
import java.util.List;

import javax.mail.Session;

import org.hibernate.Query;

public class DepositDAOImpl extends DepositDAO {
    
    public String getCodes(int start, int end) {       
        String sql = "select code from deposit2 as model where model.id >= ? and model.id <= ?";
        Query query = getCurrentSession().createSQLQuery(sql).setInteger(0, start).setInteger(1, end);
        List<String> list = query.list();
        int length = list.size();
        System.out.println("数据数目为："+length);
        //转换格式
        for(int i=0;i<length;i++){
            list.set(i,"\""+ list.get(i)+"\"");
        }
        System.out.println("数据为："+list.toString());
        return list.toString();

    }
    
    /**
     * 获取下一个卡券号
     * @param num
     * @return
     */
    public String getNextCode(int type, int num){
        String table = type == 0?"deposit":"deposit2";
        String sql = "select code from "+ table +" as model where model.id = ?";
        Query query = getCurrentSession().createSQLQuery(sql).setInteger(0, num+1);
//        System.out.print("下一个code为："+query.list().toString());
        String result = query.list().get(0).toString();        
        return result;
    }
    

}
